<?php

function register_product_hunt_post_type()
{
    $link = 'product-hunt';
    $name = '产品';
    $producthunt_labels = array(
        'name' => sprintf(__('%s', 'b2'), $name),
        'singular_name' => sprintf(__('%s', 'b2'), $name),
        'add_new' => __('添加一个产品', 'b2'),
        'add_new_item' => __('添加一个产品', 'b2'),
        'edit_item' => __('编辑产品', 'b2'),
        'new_item' => __('新的产品', 'b2'),
        'all_items' => __('所有产品', 'b2'),
        'view_item' => __('查看产品', 'b2'),
        'search_items' => __('搜索产品', 'b2'),
        'not_found' => __('没有产品', 'b2'),
        'not_found_in_trash' => __('回收站为空', 'b2'),
        'menu_name' => sprintf(__('%s', 'b2'), $name),
    );

    register_post_type(
        'producthunt',
        array(
            'labels' => $producthunt_labels,
            'has_archive' => true,
            'public' => true,
            'menu_position' => 30,
            'show_in_rest' => true,
            'menu_icon' => 'dashicons-cart',
            'taxonomies' => array('circle_tags'),
            'exclude_from_search' => false,
            'capability_type' => 'post',
            'supports' => array(
                'title',
                'comments',
                'editor',
                'author',
                'thumbnail',
                'excerpt'
            ),
            'map_meta_cap' => true,
            'yarpp_support' => true,
            'rewrite' => array('slug' => $link, 'with_front' => false),
        )
    );
}

add_action('init','register_product_hunt_post_type');

function register_product_hunt_custom_taxonomy()
{
    $name = '产品分类';
    $slug = 'product_cat';

    $arr = array(
        'name' => $name,
        'singular_name' => $name,
        'search_items' => sprintf(__('搜索%s', 'b2'), $name),
        'all_items' => sprintf(__('所有%s', 'b2'), $name),
        'parent_item' => sprintf(__('父级%s', 'b2'), $name),
        'parent_item_colon' => sprintf(__('父级%s', 'b2'), $name),
        'edit_item' => sprintf(__('编辑%s', 'b2'), $name),
        'update_item' => sprintf(__('更新%s', 'b2'), $name),
        'add_new_item' => sprintf(__('添加%s', 'b2'), $name),
        'new_item_name' => sprintf(__('%s名称', 'b2'), $name),
        'menu_name' => $name,
    );

    $args = array(
        'hierarchical' => true,
        'labels' => $arr,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'show_in_rest' => true,
        'rewrite' => array('slug' => $slug, 'with_front' => false),
    );

    register_taxonomy('productcat', array('producthunt'), $args);
}

add_action('init','register_product_hunt_custom_taxonomy');


function register_product_hunt_tags(){
    $newsflashes_slug = 'product_tags';
    $newsflashes_name = '产品';
    $arr = array(
        'name' => sprintf(__('%s标签', 'b2'), $newsflashes_name),
        'singular_name' => sprintf(__('%s标签', 'b2'), $newsflashes_name),
        'search_items' => sprintf(__('搜索%s标签', 'b2'), $newsflashes_name),
        'all_items' => sprintf(__('所有%s标签', 'b2'), $newsflashes_name),
        'parent_item' => sprintf(__('父级%s标签', 'b2'), $newsflashes_name),
        'parent_item_colon' => sprintf(__('父级%s标签', 'b2'), $newsflashes_name),
        'edit_item' => sprintf(__('编辑%s标签', 'b2'), $newsflashes_name),
        'update_item' => sprintf(__('更新%s标签', 'b2'), $newsflashes_name),
        'add_new_item' => sprintf(__('添加%s标签', 'b2'), $newsflashes_name),
        'new_item_name' => sprintf(__('%s标签名称', 'b2'), $newsflashes_name),
        'menu_name' => sprintf(__('%s标签', 'b2'), $newsflashes_name),
    );

    $args = array(
        'hierarchical' => true,
        'labels' => $arr,
        'public' => true,
        'update_count_callback' => '_update_post_term_count',
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'show_in_rest' => true,
        'rewrite' => array('slug' => $newsflashes_slug, 'with_front' => false),
    );

    register_taxonomy('product_tags', array('producthunt'), $args);
}

add_action('init', 'register_product_hunt_tags');

